package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.service.IBrandCategoryService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@Api(tags = "05.品牌与类别关联数据管理模块")
@RestController
@RequestMapping("/brand-category")
public class BrandCategoryController {
    @Autowired
    private IBrandCategoryService brandCategoryService;

    public BrandCategoryController() {
        log.debug("创建控制器对象：BrandCategoryController");
    }

    @ApiOperation("绑定品牌与类别的关联")
    @ApiOperationSupport(order = 100)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "brandId", value = "品牌id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "categoryID", value = "类别id", required = true, dataType = "long")
    })
    @PostMapping("/bind")
    public JsonResult addNew(Long brandId, Long categoryID){
        log.debug("开始处理【绑定品牌与类别的关联】的请求，品牌id:{}，类别id：{}", brandId, categoryID);
        brandCategoryService.insert(brandId, categoryID);
        return JsonResult.ok();
    }

    @ApiOperation("解绑品牌与类别的关联 ")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "品牌与类别关联数据的id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/unbind")
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理【解绑品牌与类别的关联】的请求，参数id：{}", id);
        brandCategoryService.deleteById(id);
        return JsonResult.ok();
    }
}
